﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CiDotNet.WinCalc
{
    public partial class FormCalc : Form
    {
        public FormCalc()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            int duration = int.Parse(txtPeriods.Text);
            double interest = double.Parse(txtInterest.Text);
            double presentValue = double.Parse(txtPrice.Text);
            double residualValue = double.Parse(txtResidualValue.Text);
            Calc.Math.Finance.Mode mode = rbModeBegin.Checked ? Calc.Math.Finance.Mode.BeginMode : CiDotNet.Calc.Math.Finance.Mode.EndMode;
            txtRate.Text = CiDotNet.Calc.Math.Finance.CalculateRate(duration, 12, interest, presentValue, residualValue, mode).ToString("#.##");
        }
    }
}
